# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=snapper
pkgver=0.10.2
pkgrel=3
pkgdesc="Manage filesystem snapshots and allow undo of system modifications"
url="http://snapper.io"
arch="all !armhf !armv7" # Fails to build on 32bit arches, see #12617
license="GPL-2.0-or-later"
options="!check" # 5 tests failing - https://github.com/openSUSE/snapper/issues/526
depends="dbus"
makedepends="acl-dev autoconf automake bash boost-dev
	bsd-compat-headers btrfs-progs-dev json-c-dev
	dbus-dev docbook-xsl e2fsprogs-dev gettext-dev
	libtool libxml2-dev libxslt lvm2-dev ncurses-dev
	"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-lang
	$pkgname-bash-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/openSUSE/snapper/archive/v$pkgver.tar.gz
	musl-stdout_stderr.patch
	miss-tinfo-link-to-ncurses.patch
	drift-file-path.patch"

prepare() {
	default_prepare

	sed -e 's|etc/dbus-1/system.d|usr/share/dbus-1/system.d|' \
		-i data/Makefile.am

	autoreconf -fi
	# rename cron scripts
	sed -i -e 's@suse.de-@@g' scripts/Makefile.am
	# copy cron scripts to /etc/periodic/* instead of /etc/cron.*
	sed -i -e 's/cron\./periodic\//g' scripts/Makefile.am
	# fix config location in cron scripts
	sed -i -e 's@/etc/sysconfig/@/etc/snapper/@g' scripts/snapper-daily
	sed -i -e 's@/etc/sysconfig/@/etc/snapper/@g' scripts/snapper-hourly
}

build() {
	export CXXFLAGS="$CXXFLAGS -DMUSL_LIBC=1"
	export LDFLAGS="$LDFLAGS -lintl"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sbindir=/usr/sbin \
		--disable-silent-rules \
		--with-conf=/etc/snapper \
		--disable-pam \
		--disable-zypp \
		--disable-ext4 \
		--disable-systemd \
		JSONC_CFLAGS="-I/usr/include/json-c" \
		JSONC_LIBS="-ljson-c"
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
	install -Dm644 data/sysconfig.snapper "$pkgdir"/etc/snapper/$pkgname
}

sha512sums="
bdda67908b054beee7285bb3ac97ce28276449d7719369135a7ffa74bce40000ebc89f4f059abe44f8cc7c3a09c46af446e812229290ddd10b2af053fefbc568  snapper-0.10.2.tar.gz
5baf722996706146b62fd0a0d9b321496fb122e700af2d3dfd8272de2678f29c79bc2b1a03634b04aab3f226632dfdebc5674d3128737e85bcc71461e951d95b  musl-stdout_stderr.patch
3d264f7f9156342d5bad2ac78db9c8a30ea1ac25648245631a47d1495bb6610c6b39c28a5013741063df3c08f459388c0467caaedde5ad7cebb433eb432b7a70  miss-tinfo-link-to-ncurses.patch
c2470da8a5d62a37babdacd361051bae8fb3e1be157cb7eec1563a40825d41702f6f10bb619ffcab2ea8d7407405a543b0c47997c70a744c20cc3135c0532c1f  drift-file-path.patch
"
